
$(function () {
     getYNcanglist(0);
});
//获取云南仓列表
function getYNcanglist(orderSort){
    $.ajax({   	
        url:"/yangcangclub/v1/merchandise/list/show?access_token="+access_token+"&type=5&orderSort=0"+orderSort+"&pageSize=10",
        type:'GET',
        dataType:"json",
            success:function(data){
//      	console.log(data)
            if(data.code == 1000){
                var _json=window.eval(data).data.list;
//              console.log(_json)
                var len=_json.length;
//              console.log(len)
                var _html = "";
                for(var i=0;i<len;i++){
                     _html+= '<div class=\'content\'>';
                     _html+= '<div class=\'box\'>';
                     if(i%2 == 0){
                     	 _html+= '<div class=\'text\'>';
	                     _html+= '<p class=\"tex1\">'+_json[i].name+'</p>';
	                     _html+= '<p class=\"tex2\">'+_json[i].subtitle+'</p>';
	                     _html+= '<p class=\"tex3\"><span class=\'member\'>会员价</span><span class=\'mony\'>￥'+_json[i].unitPrice+'.00</span></p>';
	                     _html+= '<div class=\'tbtn\' onclick="addChart('+_json[i].id+');"><button>加入购物车</button></div>';
	                     _html+= '</div>'
	                     _html+= '<div class=\'jpg\'><img src="'+_json[i].bannerUrl+'" ></div>';
                     }else{
                     	 _html+= '<div class=\'Text\'>';
	                     _html+= '<p class=\"tex1\">'+_json[i].name+'</p>';
	                     _html+= '<p class=\"tex2\">'+_json[i].subtitle+'</p>';
	                     _html+= '<p class=\"tex3\"><span class=\'member\'>会员价</span><span class=\'mony\'>￥'+_json[i].unitPrice+'.00</span></p>';
	                     _html+= '<div class=\'tbtn\' onclick="addChart('+_json[i].id+');"><button>加入购物车</button></div>';
	                     _html+= '</div>'
	                     _html+= '<div class=\'png\'><img src="'+_json[i].bannerUrl+'" ></div>';
                     }
                    
                     
                     _html+= '</div>';
                     _html+= '</div>';
                }
               $(".content").html(_html);
            }
        },
        error:function(data){
            layer.open({content: '请求失败，请刷新再试', skin: 'msg', time: 2});
        }
    });
}

var basePath=basePath();
function addChart(id){
    //添加到购物车。
    $.ajax({
        url:basePath+"/v1/user/access_token",
        type:'GET',
        data:{
            access_token:access_token
        },
        dataType:"json",
        success:function(json) {
            if (json.code == 1000) {
                var userInfo = json.data;
                var userMark =userInfo.user_mark;
                if(userMark==4){
                    $.ajax({
                        url:"/yangcangclub/v1/trolley/add?access_token="+access_token+"&pid="+id+"&num=1",
                        type:'GET',
                        dataType:"json",
                        success:function(data){
                            if(data.code == 1000){
                                //成功后跳转到购物车页
                                var productDetailPageUrl=basePath()+"res/gwc.html?access_token="+access_token;
                                window.location.href=productDetailPageUrl;

                            }else{
                                layer.open({content: data.msg, skin: 'msg', time: 2});
                            }
                        },
                        error:function(data){
                            layer.open({content: '请求失败，请刷新再试', skin: 'msg', time: 2});
                        }
                    });
                }else{
                    layer.open({
                        title: ['该商品为会员专享', 'background-color: #FFF;'],
                        content: '<div style="text-align: left; ">购买羊仓商城中<span style="color: red;">富硒蛋卡</span>（月卡、季卡、年卡），并通过羊仓微信服务号“羊仓会员专属”成<span style="color: red;">激活蛋卡</span>，即可成为羊仓会员</div>'
                        ,btn: ['<span style="color:#000;">激活蛋卡</span>','<span style="color:#000;">购买蛋卡</span>' ]
                        ,yes: function(index){//激活
                            layer.close(index);
                            window.location.href= "http://b.yangcangclub.com/eggcard/h5/user/order/list";
                            // window.location.href=basePath+"res/mryx.html?access_token="+access_token+"&type=1";
                        },
                        no: function (index) {//购买
                            layer.close(index);
                            window.location.href=basePath+"res/mryx.html?access_token="+access_token+"&type=1";
                        }
                    });
                }
            }
        },
        error:function(data){
            console.info(data.msg);
        }
    });
//     $.ajax({
//         url:"/yangcangclub/v1/trolley/add?access_token="+access_token+"&pid="+id+"&num=1",
//         type:'GET',
//         dataType:"json",
//         success:function(data){
//             if(data.code == 1000){
//                 //成功后跳转到购物车页
//                 var productDetailPageUrl=basePath()+"res/gwc.html?access_token="+access_token;
// //              console.log(productDetailPageUrl)
//                 window.location.href=productDetailPageUrl;
//
//             }else{
//                 layer.open({content: data.msg, skin: 'msg', time: 2});
//             }
//         },
//         error:function(data){
//             layer.open({content: '请求失败，请刷新再试', skin: 'msg', time: 2});
//         }
//     });
}




























